package com.zmj.sy.mom.srv.aps.bean.vo.base;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zmj.sy.mom.srv.aps.utils.MkBeanUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.SneakyThrows;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@NoArgsConstructor
@Getter
@Setter
public class BasePageResVo<T> extends BaseResVo {
    @ApiModelProperty("总数量")
    private long total;

    @ApiModelProperty("数据列表")
    private List<T> data;

    public BasePageResVo(long total, List<T> data) {
        this.total = total;
        this.data = data;
    }

    @SneakyThrows
    public static <T> BasePageResVo<T> of(Page<?> shiftPage, Class<T> clazz, String... ignoreProperty) {
        List<T> l = shiftPage.getRecords()
                .stream()
                .map(e -> MkBeanUtils.copyProperties(e, clazz, ignoreProperty))
                .collect(Collectors.toList());
        return new BasePageResVo<>(shiftPage.getTotal(), l);
    }


    public static <T> BasePageResVo<T> empty() {
        return new BasePageResVo<>(0, new ArrayList<>());
    }
    public static <T> BasePageResVo<T> empty(long total) {
        return new BasePageResVo<>(total, new ArrayList<>());
    }
}
